package servlets;

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import beans.DBHelper;
import beans.JobBean;

/**
 * Servlet implementation class ViewProvide
 */
@WebServlet("/ViewProvide")
public class ViewProvide extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ViewProvide() {
        super();
        // TODO Auto-generated constructor stub
    }

    protected void handViewProvide(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
    	try{
    	

		HttpSession session=request.getSession();
    	
		String provider= session.getAttribute("user").toString();
		
 
    	Connection con=DBHelper.getConnection();
    	PreparedStatement ps=DBHelper.getprepareStatement(con,"select* from providejob where provider = ?");
    	ps.setString(1, provider);
    	ResultSet rs=ps.executeQuery();
    	ArrayList<JobBean> job=new ArrayList<JobBean>();
    	while(rs.next()){
    		
    		String jobid = rs.getString("jobId");
    		String company = rs.getString("company");
    		String salary = rs.getString("salary");
    		String address = rs.getString("address");
    		String companysize = rs.getString("companysize");
    		String companytype = rs.getString("companytype");
    		String jobtype = rs.getString("jobtype");
    		
    		JobBean jobs=new JobBean(jobid, company, salary, address, companysize, companytype, jobtype, provider);
    	
    		job.add(jobs);
    	}
    	request.setAttribute("job", job);
    	}catch(Exception e){
    		e.printStackTrace();
    	}
    	request.getRequestDispatcher("viewProvideJob.jsp").forward(request, response);
    }
    
    
	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		handViewProvide(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		handViewProvide(request, response);
	}

}
